﻿import flash.geom.Point;
import flash.geom.Matrix;
class com.embedchat.skins.standart.scrollbar.ScrollBarSliderClass extends MovieClip{
	static var instanceName:String = new String ("ScrollBarSliderClass");
	static var instanceOwner:Object = com.embedchat.skins.standart.scrollbar.ScrollBarSliderClass;
	[Inspectable(name="Slider direction", defaultValue="vertical",type:String, enumeration="vertical,horizontal")]
	public var direction:String;
	[Inspectable(name="Slider width",defaultValue=16,type:Number)]
	public var canvasWidth:Number;
	[Inspectable(name="Slider height",defaultValue=17,type:Number)]	
	public var canvasHeight:Number;
	public var canvasCurveRadius:Number = 2;	
	private var broadcasterObj:Object = null;
	private var isStartMove:Boolean = false;
	
	function ScrollBarSliderClass(){
		this.useHandCursor = false;
		this.onRelease = this.onMouseOutEvent;
		this.onReleaseOutside = this.onMouseOutEvent;
		this.onRollOut = this.onMouseOutEvent;
		this.onRollOver = this.onMouseOverEvent;
		this.onPress = this.onMouseDownEvent;
		this.onMouseMove = this.onMouseMoveEvent;
		this.onMouseOutEvent();
	}
	private function onMouseMoveEvent():Void{
		if(this.isStartMove){
			var mouse:Point = new Point(_xmouse,_ymouse);
			if(this.broadcasterObj){
				this.broadcasterObj.broadcastMessage("onScrollSliderMove",this,mouse);
			}
		}
	}
	
	
	private function onMouseOutEvent():Void{
		//logic
		if(this.isStartMove){
			this.broadcasterObj.broadcastMessage("onScrollSliderRelease",this);
			this.isStartMove = false;
		}
				
		//gui		
		this.clear();
		var fillType:String = "linear"
		var colors:Array = [0xFFFFFF, 0xBCD0E8];
		var alphas:Array = [100, 100];
		var ratios:Array = [0x00, 0xFF];
		var rotation:Number = (this.direction == "vertical")?(0*Math.PI):(0.5*Math.PI);		
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(this.canvasWidth, this.canvasHeight, rotation, -2, -2);
		var spreadMethod:String = "pad";
		
		this.lineStyle(0, 0xA4B8D0, 100, true, "none", "round", "miter", 1);		
		this.beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod); 
		
		this.drawCanvas();
		this.endFill();
	}
	
	private function onMouseOverEvent():Void{
		//logic
		if(this.isStartMove){
			if(this.broadcasterObj){
				this.broadcasterObj.broadcastMessage("onScrollSliderRelease",this);
			}
			this.isStartMove = false;
		}
		//gui
		this.clear();
		var fillType:String = "linear"
		var colors:Array = [0xFFFFFF, 0xBCD0E8];
		var alphas:Array = [100, 100];
		var ratios:Array = [0x00, 0xFF];
		var rotation:Number = (this.direction == "vertical")?(0*Math.PI):(0.5*Math.PI);			
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(this.canvasWidth, this.canvasHeight, rotation, 2, 2);
		var spreadMethod:String = "pad";
		
		this.lineStyle(0, 0x52667E, 100, true, "none", "round", "miter", 1);		
		this.beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod); 
		
		this.drawCanvas();
		
		this.endFill();
	}
	private function onMouseDownEvent():Void{
		//logic
		this.isStartMove = true;
		if(this.broadcasterObj){
			this.broadcasterObj.broadcastMessage("onScrollSliderPress",this);
		}
		//gui
		
		this.clear();
		var fillType:String = "linear"
		var colors:Array = [0xBCD0E8,0xFFFFFF];
		var alphas:Array = [100, 100];
		var ratios:Array = [0x00, 0xFF];
		var rotation:Number = (this.direction == "vertical")?(0*Math.PI):(0.5*Math.PI);	
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(this.canvasWidth, this.canvasHeight, rotation, -2, -2);
		var spreadMethod:String = "pad";
		
		this.lineStyle(0, 0x52667E, 100, true, "none", "round", "miter", 1);		
		this.beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod); 
		
		this.drawCanvas();
		
		this.endFill();
	}	
	
	private function drawCanvas():Void{
		this.moveTo(this.canvasCurveRadius, 0);
		this.lineTo(this.canvasWidth-this.canvasCurveRadius, 0);
		this.curveTo(this.canvasWidth, 0, this.canvasWidth, this.canvasCurveRadius);
		this.lineTo(this.canvasWidth, this.canvasHeight-this.canvasCurveRadius);
		this.curveTo(this.canvasWidth, this.canvasHeight, this.canvasWidth-this.canvasCurveRadius, this.canvasHeight);
		this.lineTo(this.canvasCurveRadius, this.canvasHeight);
		this.curveTo(0, this.canvasHeight, 0, this.canvasHeight-this.canvasCurveRadius);
		this.lineTo(0, this.canvasCurveRadius);
		this.curveTo(0, 0, this.canvasCurveRadius, 0);
	}
	
	public function updateVerticalSlider(y:Number,height:Number):Void{
		this.canvasHeight = height;
		this._y = y;
		this.onMouseOutEvent();
	}
}